<template>
	<view class="con" v-if="oldinfo!=null">
		<view class="item" v-if="type==1">
			<view class="it">
				<view class="name">姓名</view>
				<input class="input" v-model="oldinfo.idName" type="text" disabled style="opacity: 0.6;" />
			</view>
			<view class="it">
				<view class="name">身份证号码</view>
				<view class="input" style="opacity: 0.6;">
					{{oldinfo.idNumber  | text}}
				</view>
			</view>
			<view class="it">
				<view class="name">亲属姓名</view>
				<input class="input" v-model="oldinfo.userHealthy.familyName" type="text" />
			</view>
			<view class="it" @click="show=true">
				<view class="name">亲属关系</view>
				<input class="input" v-model="oldinfo.userHealthy.relationship" type="text" disabled />
			</view>
			<view class="it">
				<view class="name">亲属联系方式</view>
				<input class="input" v-model="oldinfo.userHealthy.familyPhone" type="text" />
			</view>
			<view class="it">
				<view class="name">常用联系人</view>
				<input class="input" v-model="oldinfo.userHealthy.peopleName" type="text" />
			</view>
			<view class="it">
				<view class="name">常用联系方式</view>
				<input class="input" v-model="oldinfo.userHealthy.peoplePhone" type="text" />
			</view>
			<view class="it" v-if="oldinfo.userHealthy.diseaseId!=''||oldinfo.userHealthy.detailed!=''">
				<view class="name">疾病史</view>
				<view class="input" style="opacity: 0.6;">
					{{oldinfo.userHealthy.diseaseId}}{{oldinfo.userHealthy.detailed}}</view>
			</view>
			<view class="it" v-else>
				<view class="name">无疾病史</view>
			</view>
		</view>
		<view class="item" v-if="type==0">
			<view class="it">
				<view class="name">姓名</view>
				<input class="input" v-model="oldinfo.idName" type="text" disabled style="opacity: 0.6;" />
			</view>
			<view class="it">
				<view class="name">身份证号码</view>
				<view class="input" style="opacity: 0.6;">
					{{oldinfo.idNumber | text}}
				</view>
			</view>
			<view class="it" v-if="oldinfo.userHealthy.diseaseId!=''||oldinfo.userHealthy.detailed!=''">
				<view class="name">疾病史</view>
				<view class="input" style="opacity: 0.6;">
					{{oldinfo.userHealthy.diseaseId}}{{oldinfo.userHealthy.detailed}}</view>
			</view>
			<view class="it" v-else>
				<view class="name">无疾病史</view>
			</view>
		</view>
		<view class="btn" @click="submit" v-if="type==1">
			确认修改
		</view>
		<u-select v-model="show" :list="list" @confirm="xzgx"></u-select>
		<!-- <cityselect  v-model="value" @city-change="cityChange" @isshow="value=false"></cityselect>
		<jb  v-model="jbshow" @jb-change="jbChange" @isshow="jbshow=false"></jb> -->
	</view>
</template>

<script>
	import {
		oldinfo,
		getjkinfo
	} from "../../../api/user.js"
	import cityselect from "../../../components/cityselect.vue"
	import jb from "../../../components/jb.vue"
	export default {
		data() {
			return {
				oldinfo: null,
				list: [{
						value: '1',
						label: '子女'
					},
					{
						value: '2',
						label: '配偶'
					},
					{
						value: '3',
						label: '父母'
					}
				],
				show: false,
				type: null
			}
		},
		filters: {
			text(val) {
				var strcard = val.replace(/^(.{4})(?:\d+)(.{6})$/, "$1********$2");
				return strcard
			}
		},
		components: {
			cityselect,
			jb
		},
		onLoad() {
			uni.showLoading({
				title: "加载中..."
			})
			let data = uni.getStorageSync("user")
			this.type = data.userType
			this.getinfo()
		},
		methods: {
			async getinfo() {
				let res = await this.get(getjkinfo)
				this.oldinfo = res.data
			},
			xzgx(e) {
				console.log(e)
				this.oldinfo.userHealthy.relationship = e[0].label
			},
			async submit() {
				if (!this.$u.test.chinese(this.oldinfo.userHealthy.familyName.trim())) {
					this.msg("未填写正确的亲属姓名", "none")
					return
				}
				if (!this.$u.test.mobile(this.oldinfo.userHealthy.familyPhone)) {
					this.msg("未填写正确的亲属手机号", "none")
					return
				}
				if (!this.$u.test.chinese(this.oldinfo.userHealthy.peopleName.trim())) {
					this.msg("未填写正确的常用联系人姓名", "none")
					return
				}
				if (!this.$u.test.mobile(this.oldinfo.userHealthy.peoplePhone)) {
					this.msg("未填写正确的常用联系人手机号", "none")
					return
				}
				this.showMd("确认修改", () => {
					this.post(oldinfo, {
						familyName: this.oldinfo.userHealthy.familyName,
						familyPhone: this.oldinfo.userHealthy.familyPhone,
						relationship: this.oldinfo.userHealthy.relationship,
						peopleName: this.oldinfo.userHealthy.peopleName,
						peoplePhone: this.oldinfo.userHealthy.peoplePhone
					}).then(res => {
						this.msg('修改成功')
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							})
						}, 1000)
					})
				})
			}
		}
	}
</script>

<style>
	.bz {
		height: 28rpx;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: bold;
		line-height: 28rpx;
		color: #F09238;
		opacity: 1;
		margin: 20rpx 0;
	}

	.l_item {
		margin-top: 20rpx;
	}

	.tt {
		height: 37rpx;
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 400;
		line-height: 37rpx;
		color: #999999;
		opacity: 1;
		margin-top: 30rpx;
		margin-bottom: 20rpx;
	}

	.phonebox {
		height: 60rpx;
		display: flex;
		align-items: center;
		padding-bottom: 20rpx;
		border-bottom: 1px #d5d5d5 solid;
		justify-content: space-between;
	}

	.lname {
		height: 45rpx;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: bold;
		line-height: 45rpx;
		color: #F09238;
		opacity: 1;
		margin-bottom: 20rpx;
	}

	.btn {
		width: 690rpx;
		height: 66rpx;
		background: #F09238;
		opacity: 1;
		border-radius: 48rpx;
		text-align: center;
		line-height: 66rpx;
		color: #FFFFFF;
	}

	.title {
		height: 45rpx;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: bold;
		line-height: 45rpx;
		color: #333333;
		opacity: 1;
	}

	.sexit {

		border-radius: 4px;
		width: 82rpx;
		height: 38rpx;
		background: #F0F0F0;
		opacity: 1;
		border-radius: 4rpx;
		text-align: center;
		line-height: 38rpx;
		font-size: 24rpx;
		margin-left: 10rpx;
		color: #999999;
	}

	.active {
		background-color: #F09238;
		color: #FFFFFF;
	}

	.sex {
		display: flex;
		align-items: center;
	}

	.input {
		text-align: right;
	}

	.it {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 80rpx;
	}

	.item {
		width: 690rpx;
		background: #FFFFFF;
		box-shadow: 0px 0px 10px rgba(149, 149, 149, 0.16);
		opacity: 1;
		border-radius: 8rpx;
		padding: 20rpx;
		margin-bottom: 50rpx;
	}

	.con {
		padding: 30rpx;

	}
</style>
